package org.one.stone.soup.db.indexing;

import java.util.ArrayList;
import java.util.List;

import org.one.stone.soup.db.processors.JSON;

public class TimeDataIndex implements Index {
	
	public class TimeEntry {
		TimeEntry(long time,long id) {
			this.time = time;
			this.id= id;
		}
		long time;
		long id;
	}
	
	private List<TimeEntry> list;
	
	public void index(long id,long time) {
		list.add( new TimeEntry(time,id) );
	}
	
	public Long[] findWithinPeriod(long startTime,long endTime) {
		List<Long> results = new ArrayList<Long>();
		for(TimeEntry entry: list) {
			if(entry.time >=startTime && entry.time <= endTime) {
				results.add(entry.id);
			}
		}
		return results.toArray(new Long[]{});
	}

	public void index(long index, JSON json) {
		index( index,json.getLong("forecastTime") );
	}
}
